package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    private Addressbook aCon;
    
    public AddressCtr()
    {
        aCon = Addressbook.getInstance();
    }
    
    //Dummy implementation: after implementing the model layer 
    //objects of class Person are to be returned, not String
    public Person findPerson(long id)
    {
        //this method is to search the container for a person
        //with an id-number equal to the parameter id
        //when person is found, the method is to call print-methods in the TUI layer
        return aCon.getID(id);
    }
    
    public void createPerson(long id, String name, String address, String postalnr, String city, String phone)
    {   
       //creates a Person object and stores it in the container
       Person p = new Person(id, name , address, postalnr, city , phone);
       aCon.addPerson(p);
    }
    
    public boolean deletePerson(long id)
    {
        //search for the person and delete the object from the container
        return aCon.deletePerson(id);
    }
    
    public void updatePerson(long id, String name, String address, String postalnr, String city, String phone)
    {
        Person person = aCon.getID(id);
        
        person.setName(name);
        person.setAddress(address);
        person.setPostalnr(postalnr);
        person.setCity(city);
        person.setPhone(phone);
    }
    
    public ArrayList listAllPersons()
    {
          return aCon.getArrayList();
    }
    
    public Person getPerson(int index)
    {
        return aCon.getPersonIndex(index);
    }
}
